package com.naiterui.ehp.bs.doctor.controller.inner;

import com.naiterui.ehp.bp.constants.SwaggerTag;
import com.naiterui.ehp.bp.support.exception.BusinessException;
import com.naiterui.ehp.bp.support.exception.PublicService;
import com.naiterui.ehp.bp.support.exception.ResponseVO;
import com.naiterui.ehp.bs.doctor.exception.ExceptionCodes;
import com.naiterui.ehp.bs.doctor.service.IHospitalService;
import com.naiterui.ehp.bs.doctor.vo.HospitalVO;
import java.util.List;

import io.swagger.annotations.Api;
import lombok.extern.slf4j.Slf4j;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.util.StringUtils;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.ResponseBody;
import org.springframework.web.bind.annotation.RestController;

/**
 * @Description 医院接口
 * @Author gongbaoqiang
 * @Date 2020/8/7 5:18 PM
 */
@Slf4j
@RestController
@RequestMapping("ad/inner/hospital")
@Api(tags = {SwaggerTag.DOCTOR + SwaggerTag.INNER_API + SwaggerTag.BASIC_INFO})
public class AdInnerHospitalController {

    @Autowired
    private IHospitalService hospitalService;
    /**
     * <根据城市和关键字搜索>
     * @param cityName
     * @return String <返回值描述>
     * @Throws 异常信息
     */
    @RequestMapping("city/list")
    @ResponseBody
    public ResponseVO<List<HospitalVO>> getListByCity(String cityName, String keyword) throws BusinessException {
        log.info("获取定位城市的医院：cityName=" + cityName + ",keyword=" + keyword);
        List<HospitalVO> voList = null;
        if (StringUtils.isEmpty(cityName) && StringUtils.isEmpty(keyword)) {
            log.error("城市与医院名为空,cityName=" + cityName + ",keyword=" + keyword);
            throw new BusinessException(ExceptionCodes.PARAM_ERROR);
        }
        try {
            voList = hospitalService.getHospitalByCity(cityName, keyword);
        } catch (Exception e) {
            e.printStackTrace();
            log.error("获取医院列表异常,cityName=" + cityName);
            throw new BusinessException(ExceptionCodes.FAILED);
        }
        return PublicService.returnResponseVO(voList);
    }
}
